package com.example.springbootdemo.Service;

import java.util.Date;
import java.util.List;

import com.example.springbootdemo.entity.Banner;
import com.example.springbootdemo.mappers.BannerMapper;
import com.example.springbootdemo.utils.PageResult;
import com.example.springbootdemo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * bannersService业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@Service
public class BannerServiceImpl implements IBannerService 
{
    @Autowired
    private BannerMapper bannerMapper;

    /**
     * 查询banners
     * 
     * @param id banners主键
     * @return banners
     */
    @Override
    public Banner selectBannerById(Long id)
    {
        return bannerMapper.selectBannerById(id);
    }

    @Override
    public PageResult selectBannerList(Banner banner, int pageNum, int pageSize) {
        //调用pageHelper插件
        PageHelper.startPage(pageNum,pageSize);
        List<Banner> list =bannerMapper.selectBannerList(banner);   //分页数据
        System.out.println(list.size());
        PageInfo<Banner> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;
    }

    /**
     * 查询banners列表
     * 
     * @param banner banners
     * @return banners
     */
//    @Override
//    public PageResult selectBannerList(Banner banner,int pageNum,int pageSize);
//    {
//        PageHelper.startPage(pageNum,pageSize);
//        List<Banner> list = bannerMapper.selectBannerList(banner);
//        System.out.println(list.size());
//        PageInfo<Banner> pageInfo = new PageInfo<>(list);
//        PageResult pageResult = PageUtils.getPageResult(pageInfo);
//        return pageResult;
//    }

    /**
     * 新增banners
     * 
     * @param banner banners
     * @return 结果
     */
    @Override
    public int insertBanner(Banner banner)
    {
        banner.setCreateTime(new Date());
        return bannerMapper.insertBanner(banner);
    }

    /**
     * 修改banners
     * 
     * @param banner banners
     * @return 结果
     */
    @Override
    public int updateBanner(Banner banner)
    {
        banner.setUpdateTime(new Date());
        return bannerMapper.updateBanner(banner);
    }

    /**
     * 批量删除banners
     * 
     * @param ids 需要删除的banners主键
     * @return 结果
     */
    @Override
    public int deleteBannerByIds(Long[] ids)
    {
        return bannerMapper.deleteBannerByIds(ids);
    }

    /**
     * 删除banners信息
     * 
     * @param id banners主键
     * @return 结果
     */
    @Override
    public int deleteBannerById(Long id)
    {
        return bannerMapper.deleteBannerById(id);
    }
}
